//
//  MGAccountTool.m
//  MaiMaiGo
//
//  Created by 孙鹏飞 on 2017/4/7.
//  Copyright © 2017年 qian. All rights reserved.
//  专门处理账号的业务（账号存储和读取）

#import "MGAccountTool.h"

@implementation MGAccountTool
#define MGUser [NSUserDefaults standardUserDefaults]
#define MGCITY [NSUserDefaults standardUserDefaults]


+ (void)saveAccount:(NSArray *)account {
    
    // 保存数据 用户信息：用户名 密码
    [MGUser setObject:account forKey:@"account"];
    [MGUser setObject:[account objectAtIndex:0] forKey:@"username"];
    [MGUser setObject:[account objectAtIndex:1] forKey:@"password"];
    
    [MGUser synchronize];
}

+ (NSArray *)getAccount {
    NSArray * array = [MGUser objectForKey:@"account"];
    return array;
}

+(NSString *)getUsername {
    NSString * username = [MGUser objectForKey:@"username"];
    return username;
}

+(NSString *)getPassword {
    NSString * password = [MGUser objectForKey:@"password"];
    return password;
}

+ (void)saveUid:(NSString *)uid
{
    [MGUser setObject:uid forKey:@"uid"];
    [MGUser synchronize];
}

+ (NSString *)getUid
{
    NSString * uid = [MGUser objectForKey:@"uid"];
    if (!uid) {
        uid =@"";
    }
    return uid;
}


+ (void)saveCard_id:(NSString *)card_id
{
    [MGUser setObject:card_id forKey:@"card_id"];
    [MGUser synchronize];
}

+ (NSString *)getCard_id
{
    NSString * card_id = [MGUser objectForKey:@"card_id"];
    return card_id;
}

+ (void)saveStatus:(NSString *)status
{
    [MGUser setObject:status forKey:@"status"];
    [MGUser synchronize];
}

+ (NSString *)getStatus
{
    NSString * status = [MGUser objectForKey:@"status"];
    if (!status) {
        status =@"";
    }
    return status;
}


+ (void)saveTel:(NSString *)tel
{
    [MGUser setObject:tel forKey:@"tel"];
    [MGUser synchronize];
}

+ (NSString *)getTel
{
    NSString * tel = [MGUser objectForKey:@"tel"];
    if (!tel) {
        tel =@"";
    }
    return tel;
}

+ (void)removeAccount
{
    [MGUser removeObjectForKey:@"account"];
    [MGUser removeObjectForKey:@"username"];
    [MGUser removeObjectForKey:@"password"];
    [MGUser removeObjectForKey:@"tel"];
    [MGUser removeObjectForKey:@"uid"];
    [MGUser removeObjectForKey:@"status"];
    [MGUser synchronize];
}

+ (void)saveCity:(NSArray *)city {
    [MGCITY setValue:city forKey:@"LocalCity"];
    [MGCITY synchronize];
}

+ (NSArray *)getCity {
    NSArray * array = [MGUser objectForKey:@"LocalCity"];
    return array;
}


@end
